package com.anyonavinfo.cpaddemo.view.settingsview;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.anyonavinfo.cpaddemo.R;

/**
 * Created by ZuiC on 2017/2/5.
 */

public class SettingListAdapter extends RecyclerView.Adapter {

    private final static int SIZE = 9;
    private OnRecyclerViewListener onRecyclerViewListener;
    private String[] settingsInfo = { "无线设置", "WIFI密码设置","蓝牙设置", "时间设置","背景设置", "系统切换",
            "夜间模式","一键清理","关于"};
    private int[] settingsIcon = { R.drawable.icon_settings_wifi, R.drawable.icon_settings_wifipw
            , R.drawable.icon_settings_bluetooth,R.drawable.icon_settings_time,
            R.drawable.icon_settings_background,R.drawable.icon_settings_systemswitch,
            R.drawable.icon_settings_nightmode,R.drawable.icon_settings_cleanprogress,
            R.drawable.icon_settings_aboutinfo};

    public void setOnRecyclerViewListener(OnRecyclerViewListener onRecyclerViewListener) {
        this.onRecyclerViewListener = onRecyclerViewListener;
    }

    public interface OnRecyclerViewListener {
        void onItemClick(int position);
    }

    public SettingListAdapter(){

    }

    public void setSettingItemInfo(int i, String info, int icon){
        settingsInfo[i] = info;
        settingsIcon[i] = icon;
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rv_settingslist, null);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(lp);
        return new SettingsViewHold(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        SettingsViewHold viewHold = (SettingsViewHold) holder;
        viewHold.ivSettingIcon.setImageResource(settingsIcon[position]);
        viewHold.tvSettingInfo.setText(settingsInfo[position]);
        viewHold.position = position;
    }

    @Override
    public int getItemCount() {
        return SIZE;
    }

    class SettingsViewHold extends RecyclerView.ViewHolder implements View.OnClickListener{

        private ImageView ivSettingIcon;
        private TextView tvSettingInfo;
        private View rootView;
        private int position;

        public SettingsViewHold(View itemView) {
            super(itemView);
            ivSettingIcon = (ImageView) itemView.findViewById(R.id.iv_settingicon);
            tvSettingInfo = (TextView) itemView.findViewById(R.id.tv_settinginfo);

            rootView = itemView.findViewById(R.id.tv_settinginfo);
            rootView.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if (null != onRecyclerViewListener) {
                onRecyclerViewListener.onItemClick(position);
            }
        }
    }
}
